package com.gitee.pagekit;

import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wxy
 * @version 1.0
 * @date 2024/5/11 18:00
 */
@Configuration
@ConditionalOnClass({SqlSessionFactory.class})
@EnableConfigurationProperties({PageProperties.class})
public class PageKitAutoConfiguration {

    private static final Log log = LogFactory.getLog(PageKitAutoConfiguration.class);

    private final PageProperties pageProperties;

    public PageKitAutoConfiguration(PageProperties pageProperties){
        this.pageProperties = pageProperties;
    }

    @Bean
    public Boolean mysqlLogInterceptor(SqlSessionFactory sqlSessionFactory){
        MysqlPageInterceptor mysqlPageInterceptor = new MysqlPageInterceptor(this.pageProperties);
        sqlSessionFactory.getConfiguration().addInterceptor(mysqlPageInterceptor);
        log.debug("mysqlPageInterceptor init");
        return Boolean.TRUE;
    }
}
